package com.huike.web.controller.clues;

import com.huike.clues.domain.TbActivity;
import com.huike.clues.result.TableDataInfoActivityList;
import com.huike.clues.result.TableDataInfoActivityParams;
import com.huike.clues.service.TbActivityService;
import com.huike.common.annotation.Log;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 活动管理Controller
 *
 * @author ruoyi
 * @date 2021-04-01
 */
@Api(tags = "活动管理相关接口")
@RestController
@RequestMapping("/clues/activity")
public class TbActivityController extends BaseController {
    @Resource
    private TbActivityService tbActivityService;

    /**
     * 查询活动管理列表
     */
    @PreAuthorize("@ss.hasPermi('clues:activity:list')")
    @GetMapping("/list")
    public TableDataInfoActivityList list(TbActivity tbActivity)
    {
        startPage();
        List<TbActivity> list = tbActivityService.selectTbActivityList(tbActivity);
        Map<String,Object> countParms=tbActivityService.getCountByStatus();
        TableDataInfo tableDataInfo = getDataTable(list, countParms);
        TableDataInfoActivityList tableDataInfoActivityList = new TableDataInfoActivityList();
        BeanUtils.copyProperties(tableDataInfo,tableDataInfoActivityList);
        TableDataInfoActivityParams params = new TableDataInfoActivityParams();
        BeanUtils.copyProperties(tableDataInfo.getParams(),params);
        tableDataInfoActivityList.setParams(params);
        return tableDataInfoActivityList;
    }


    @ApiOperation("获取状态为为2的渠道活动列表")
    @GetMapping("/listselect/{channel}")
    public AjaxResult<List<TbActivity>> list(@PathVariable("channel")  String channel)
    {
        TbActivity tbActivity =new TbActivity();
        tbActivity.setChannel(channel);
        tbActivity.setStatus("2");
        return AjaxResult.success(tbActivityService.selectTbActivityList(tbActivity));
    }

    /**
     * 获取活动管理详细信息
     */
    @ApiOperation("获取活动管理详细信息")
    @PreAuthorize("@ss.hasPermi('clues:activity:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<TbActivity> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tbActivityService.selectTbActivityById(id));
    }

    /**
     * 新增活动管理
     */
    @ApiOperation("新增活动管理")
    @PreAuthorize("@ss.hasPermi('clues:activity:add')")
    @Log(title = "活动管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult<Integer> add(@RequestBody TbActivity tbActivity)
    {
        return toAjax(tbActivityService.insertTbActivity(tbActivity));
    }


    /**
     * 修改活动管理
     */
    @ApiOperation("修改活动管理")
    @PreAuthorize("@ss.hasPermi('clues:activity:edit')")
    @Log(title = "活动管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult<Integer> edit(@RequestBody TbActivity tbActivity)
    {
        return toAjax(tbActivityService.updateTbActivity(tbActivity));
    }

    /**
     * 删除活动管理
     */
    @ApiOperation("删除活动管理")
    @PreAuthorize("@ss.hasPermi('clues:activity:remove')")
    @Log(title = "活动管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Integer> remove(@PathVariable Long[] ids)
    {
        return toAjax(tbActivityService.deleteTbActivityByIds(ids));
    }
}
